package com.zjzywl.smoke.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.zjzywl.smoke.repository.AuthorityRepository;
import com.zjzywl.smoke.repository.SysUserRepository;
import com.zjzywl.smoke.entity.Authority;
import com.zjzywl.smoke.entity.SysUser;

@RestController
public class CustomUserController {
	@Autowired
	private SysUserRepository userRepository;
	@Autowired
	private AuthorityRepository authorityRepository;

	@RequestMapping(value = "/username/{username}")
	public Authority Username(@PathVariable("username") String loginName) {
		System.out.println(loginName);
		SysUser people = userRepository.findByLoginName(loginName);
		System.out.println(people);
		System.out.println(people.getRole());
		if (people != null) {
			Authority authority = authorityRepository.findRoleById(people.getRole().getRoleId());
			return authority;
		} else {
			return null;
		}

	}

	@RequestMapping(value = "/people/{username}")
	public SysUser getPeople(@PathVariable("username") String loginName) {
		System.out.println(loginName);
		SysUser people = userRepository.findByLoginName(loginName);
		return people;

	}

}